//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <bsp.h>
#include <mmu.h>
#include <init.h>

#include "cache.h"

#include <regs.h>

#include <pit/timer.h>

STATIC DECL_CODEINIT void ParseBootCommandLine()
{
}

#if defined(_GNUC)
EXTERN_C unsigned int _gp;
#elif defined(_EVC)
#else
#error unknown compiler
#endif

EXTERN_C uint32_t   g_kernelStack;

DECL_ASMLINKAGE DECL_CODEINIT void BspStartup()
{
#if defined(_GNUC)
    unsigned long a_gp;

    a_gp = (unsigned int)&_gp;
    ASM ("move $28, %0"
        ::"r"(a_gp):"$28");
#elif defined(_EVC)
// TODO(mips): Initialize the gp register!
#else
#error unknown compiler
#endif

    InitConsole();

    //
    // It's a temporary exception stack,
    // before the first real kernel thread startup.
    //
    g_kernelStack = 0x80050000;

    // Setup
    KrnSetup(KERNEL_PHYSBASE, KERNEL_IMAGEPHYSBASE, 0, 0, 0, 0);

    // Initialize
    InitBootModules();

    ParseBootCommandLine();

    InitMemoryZones();

    InitPIC();

    InitPIT();

    if (!KrnInitialize()) {
        BspHalt();
    }

    KrnStartup();

    assert0msg("Kernel startup failed");
    BspHalt();
}

BspGlobals bsp = {
    "MIPS",                   // *szCpuDescription
    "it8172",                 // *szBoardDescription
    
    KERNEL_PHYSBASE,          // paKernelPhysBase
    KERNEL_IMAGEPHYSBASE,     // paKernelImagePhysBase
    
    NULL,                     // *pMemoryZones
    0,                        // uNumberOfMemoryZones
    
    NULL,                     // *pMemoryHoles
    0,                        // uNumberOfMemoryHoles
    
    0,                        // uDmaPreferredZoneNo
    0,                        // uKernelPreferredZoneNo
    0,                        // uUserPreferredZoneNo
    
    {0, 0},                   // regionOfInitStack
    
    NULL,                     // *pBootModules
    0,                        // uNumberOfBootModules
    {0, 0},                   // regionOfBootModules
    
    NULL,                     // *szBootCommandLine
    
    0,                        // uIrqBase
    8,                        // uNumberOfIrqs
    
    PIT_Irq,                  // irqOfPIT
    IPL0                      // iplOfPIT
};
